<template>
    <div>
        <Modal width="600"
               v-model="modalcode.addModalFlag"
               @on-ok="ok"
               @on-cancel="cancel"
               draggable
               scrollable
               title="字典添加">
            <Form :label-width="80">
                <FormItem label="字段类型:">
                    <Row>
                        <Col span="16">
                            <Select v-if="!newcodetype" v-model="codeData.codeType" >
                                <Option  v-for="index in codeTypeList" :key="index" :value="index">{{index}}</Option>
                            </Select>
                            <Input  v-if="newcodetype" placeholder="请输入新类型" v-model="codeData.codeType" />
                        </Col>
                        <Col span="8">
                            <Button :icon="newcodetype?'md-arrow-back':'md-add'"
                                    @click="newcodetype?newcodetype=false:newcodetype=true">
                                {{newcodetype?'返回下拉框':'新类型？'}}
                            </Button>
                        </Col>
                    </Row>
                </FormItem>
                <FormItem label="字段名称:">
                        <Input v-model="codeData.codeName"/>
                </FormItem>
            </Form>
        </Modal>
    </div>
</template>

<script>
    export default {
       props:{
           modalcode:{
               addModalFlag:false
           }
       },
        data(){
            return{
                newcodetype:false,
                codeData:{
                    codeType:null,
                    codeName:null
                },
                codeTypeList:[]
            }
        },
        methods:{
            ok(){
                this.http.post("/code/saveaddcode",this.qs.stringify(this.codeData)).then(res=>{
                    if(res.data){
                        this.$parent.getAllCode()
                        this.$Message.success("添加成功！！！")
                        this.$emit("changeAddModel",false)
                    }else {
                        his.$Message.success("操作失败！！！")
                        this.$emit("changeAddModel",false)
                    }
                }).finally(res=>{
                    this.$emit("changeAddModel",false)
                }).catch(res=>{
                    this.$Message.error("出错啦！！！")
                })
            },
            cancel(){
                this.$emit("changeAddModel",false)
            },
        },created() {
           this.http.get("/code/getAllCodeType").then(res=>{
                this.codeTypeList = res.data
           })
        }
    }
</script>

<style scoped>
    Button{
        float: right;
    }
</style>
